package cn.tedu.sp04.controller;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.sp01.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * @ClassName OrderController
 * @Description:类描述
 * @Author Tedu
 * @Date 2021/6/22 15:55
 * @Version V1.0
 **/
@Slf4j
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId){
        Order order = orderService.getOrder(orderId);
       return JsonResult.ok().data(order);
    }
    @GetMapping("/addOrder")
    public JsonResult<?> addOrder(){
        //写死一个订单数据
        Order order = new Order();
        order.setId("12123")
                .setUser(new User(8,null,null))
                .setItems(Arrays.asList(new Item[] {
                        new Item(1,"商品1",2),
                        new Item(2,"商品2",6),
                        new Item(3,"商品3",4),
                        new Item(4,"商品4",3)

                }));
        orderService.addOrder(order);
       return JsonResult.ok().data(order);
    }

}
